// pages/Storelist/Storelist.js
var axios = require("../util/request.js")
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    index: '',
    index1: "",
    listData: "",
    Datalist: "",
    multiIndex2: '',
    multiIndex22: '',

    floor: "",
    commercial: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.shoplist()
  },
  // 查询所有
  shoplist(data) {
    axios.getData('mall_manager/get_shop_retail_for_mall', this.shoplist1);
  },
  shoplist1: function (res) {
    //  console.log(res.data.data[0].shop_list)
    var json = { retail_form_name: "所有", retail_form_id: '222' }
    res.data.data[0].retail_form_list.unshift(json)
    var json1 = { floor_id: '333', floor_name: '所有' }
    res.data.data[0].floor_list.unshift(json1)
    this.setData({
      listData: res.data.data[0].shop_list,
      Datalist: res.data.data[0].shop_list,
      index: res.data.data[0].floor_list,
      index1: res.data.data[0].retail_form_list,
    })
  },
  bindPickerChange: function (e) {
  
    var that = this;
    
    if (this.data.index[e.detail.value].floor_name == '所有') {
      
      var list = []
      // 楼层筛选
      
      if (this.data.commercial == '' || this.data.commercial === null || this.data.commercial === undefined) {
        
        
        that.setData({
          listData:that.data.Datalist,
          multiIndex2: e.detail.value
        })
      } else if (this.data.commercial==='0') {
        
        that.setData({
          listData: that.data.Datalist,
          multiIndex2: e.detail.value
        })
       
      }else{
        
        for (var i = 0; i < this.data.Datalist.length; i++) {

          if (this.data.Datalist[i].retail_form_name == this.data.index1[this.data.commercial].retail_form_name) {
            list.push(this.data.Datalist[i])
          }
        }
        this.setData({
          listData: list,
          multiIndex2: e.detail.value
        })
      }
     

    } else {
      var list = []
      // 楼层筛选
      if (this.data.commercial == '' || this.data.commercial === null || this.data.commercial === undefined) {
        
        for (var i = 0; i < this.data.Datalist.length; i++) {

          if (this.data.Datalist[i].floor_name == this.data.index[e.detail.value].floor_name) {
            list.push(this.data.Datalist[i])
          }
        }
      } else {
        
        
        if (this.data.index1[this.data.commercial].retail_form_name == '所有') {
          
          for (var i = 0; i < this.data.Datalist.length; i++) {

            if (this.data.Datalist[i].floor_name == this.data.index[e.detail.value].floor_name) {
              list.push(this.data.Datalist[i])
            }
          }
        }else{
          
          for (var i = 0; i < this.data.Datalist.length; i++) {

            if (this.data.Datalist[i].floor_name == this.data.index[e.detail.value].floor_name && this.data.Datalist[i].retail_form_name == this.data.index1[this.data.commercial].retail_form_name) {
              list.push(this.data.Datalist[i])
            }
          } 
        }

       
      }
      this.setData({
        listData: list,
        multiIndex2: e.detail.value
      })
    }
    this.setData({
      floor: e.detail.value
    })

  },
  bindPickerChange2: function (e) {
    var that = this;
   
    if (this.data.index1[e.detail.value].retail_form_name == '所有') {
      
      var list = []
      // 业态筛选
      
      if (this.data.floor == '' || this.data.floor === null || this.data.floor === undefined) {
        // console.log('11')
        // for (var i = 0; i < this.data.Datalist.length; i++) {

        //   if (this.data.Datalist[i].retail_form_name == this.data.index1[e.detail.value].retail_form_name) {
        //     list.push(this.data.Datalist[i])
        //   }
        // }
        that.setData({
          listData: that.data.Datalist,
          multiIndex22: e.detail.value
        })
      } else if (this.data.floor==='0'){
        that.setData({
          listData: that.data.Datalist,
          multiIndex22: e.detail.value
        })
      }else {
       
        for (var i = 0; i < this.data.Datalist.length; i++) {

          if (this.data.Datalist[i].floor_name == this.data.index[this.data.floor].floor_name) {
            list.push(this.data.Datalist[i])
          }
        }
        this.setData({
          listData: list,
          multiIndex22: e.detail.value
        })
      }
     

    } else {
      var list = []
      // 业态筛选
     
      if (this.data.floor == '' || this.data.floor === null || this.data.floor === undefined) {
        
        for (var i = 0; i < this.data.Datalist.length; i++) {

          if (this.data.Datalist[i].retail_form_name == this.data.index1[e.detail.value].retail_form_name) {
            list.push(this.data.Datalist[i])
          }
        }
      } else if (this.data.floor==='0'){
        for (var i = 0; i < this.data.Datalist.length; i++) {

          if (this.data.Datalist[i].retail_form_name == this.data.index1[e.detail.value].retail_form_name) {
            list.push(this.data.Datalist[i])
          }
        }
      } else {
        
        for (var i = 0; i < this.data.Datalist.length; i++) {

          if (this.data.Datalist[i].floor_name == this.data.index[this.data.floor].floor_name && this.data.Datalist[i].retail_form_name == this.data.index1[e.detail.value].retail_form_name) {
            list.push(this.data.Datalist[i])
          }
        }
      }
      this.setData({
        listData: list,
        multiIndex22: e.detail.value
      })
    }
  

    this.setData({
      commercial: e.detail.value
    })



    this.setData({
      multiIndex22: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})